package com.dkd.manage.mapper;

import java.util.List;
import com.dkd.manage.domain.Channel;
import com.dkd.manage.domain.vo.ChannelVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 售货机货道Mapper接口
 * 
 * @author yuwei
 * @date 2024-09-02
 */
public interface ChannelMapper 
{
    /**
     * 查询售货机货道
     * 
     * @param id 售货机货道主键
     * @return 售货机货道
     */
    public Channel selectChannelById(Long id);

    /**
     * 查询售货机货道列表
     * 
     * @param channel 售货机货道
     * @return 售货机货道集合
     */
    public List<Channel> selectChannelList(Channel channel);

    /**
     * 新增售货机货道
     * 
     * @param channel 售货机货道
     * @return 结果
     */
    public int insertChannel(Channel channel);


    /**
     * 批量新增售货机
     * @param channels
     * @return
     */
    public int batchInsertChannels(List<Channel> channels);

    /**
     * 修改售货机货道
     * 
     * @param channel 售货机货道
     * @return 结果
     */
    public int updateChannel(Channel channel);

    /**
     * 删除售货机货道
     * 
     * @param id 售货机货道主键
     * @return 结果
     */
    public int deleteChannelById(Long id);

    /**
     * 批量删除售货机货道
     * 
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteChannelByIds(Long[] ids);


    /**
     * 根据商品id查询货道数量
     * @param skuIds
     * @return
     */
    int countChannelBySkuIds(Long[] skuIds);




    /**
     * 根据售货机编号查询货道列表
     * @param innerCode
     * @return
     */
    List<ChannelVo> selectChannelVoListByInnerCode( String innerCode);


    /**
     * 根据售货机编号和货道编号查询货道信息
     * @param innerCode
     * @param channelCode
     * @return
     */
    @Select("select * from tb_channel where inner_code=#{innerCode} and channel_code = #{channelCode}")
    Channel getChannelInfo(@Param("innerCode") String innerCode,@Param("channelCode") String channelCode);


    /**
     * 批量更新货道信息
     * @param channelList
     * @return
     */
    int batchUpdateChannels(List<Channel> channelList);





    /**
     * 根据售货机编号查询货道销售情况
     * @param innerCode
     * @return
     */
    @Select("SELECT c.channel_code AS channelCode,s.sku_name AS skuName,COUNT(DISTINCT o.id) AS saleNum FROM tb_channel c LEFT JOIN tb_sku s ON c.sku_id = s.sku_id LEFT JOIN tb_order o ON o.channel_code = c.channel_code WHERE c.inner_code = #{innerCode} AND s.sku_id IS NOT NULL GROUP BY c.channel_code, s.sku_name;")
    List<ChannelVo> selectChannelVoSaleListByInnerCode( String innerCode);


}
